package com.lee.lease.web.app.service.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lee.lease.model.entity.ApartmentInfo;
import com.lee.lease.model.entity.FacilityInfo;
import com.lee.lease.model.entity.LabelInfo;
import com.lee.lease.model.enums.RedisConstant;
import com.lee.lease.web.app.mapper.*;
import com.lee.lease.web.app.service.ApartmentInfoService;
import com.lee.lease.web.app.vo.apartment.ApartmentDetailVo;
import com.lee.lease.web.app.vo.graph.GraphVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author liubo
 * @description 针对表【apartment_info(公寓信息表)】的数据库操作Service实现
 * @createDate 2023-07-26 11:12:39
 */
@Service
public class ApartmentInfoServiceImpl extends ServiceImpl<ApartmentInfoMapper, ApartmentInfo>
        implements ApartmentInfoService {

    @Autowired
    private GraphInfoMapper graphInfoMapper;
    @Autowired
    private LabelInfoMapper labelInfoMapper;
    @Autowired
    private FacilityInfoMapper facilityInfoMapper;
    @Autowired
    private RoomInfoMapper roomInfoMapper;

    @Override
    public ApartmentDetailVo findApartmentDetailById(Integer id) {
        ApartmentInfo apartmentInfo = baseMapper.getApartmentInfo(id);
        if (apartmentInfo == null) {
            return null;
        }
        ApartmentDetailVo apartmentDetailVo = new ApartmentDetailVo();
        BeanUtils.copyProperties(apartmentInfo, apartmentDetailVo);
        List<GraphVo> graphVoList = graphInfoMapper.findGraphVoByApartmentId(id.longValue());
        List<LabelInfo> labelInfoList = labelInfoMapper.findByApartmentId(id.longValue());
        List<FacilityInfo> facilityInfoList = facilityInfoMapper.findFacilityByApartmentId(id);
        boolean isDelete = baseMapper.selectIsDelete(id);
        BigDecimal minRent = roomInfoMapper.selectMinRent(id);


        apartmentDetailVo.setGraphVoList(graphVoList);
        apartmentDetailVo.setLabelInfoList(labelInfoList);
        apartmentDetailVo.setFacilityInfoList(facilityInfoList);
        apartmentDetailVo.setIsDelete(isDelete);
        apartmentDetailVo.setMinRent(minRent);
        return apartmentDetailVo;
    }

    @Override
    public ApartmentDetailVo findApartmentDetailById1(Integer id) {
        ApartmentDetailVo apartmentDetailVo = baseMapper.getApartmentInfo1(id);
        if (apartmentDetailVo == null) {
            return null;
        }
        List<GraphVo> graphVoList = graphInfoMapper.findGraphVoByApartmentId(id.longValue());
        List<LabelInfo> labelInfoList = labelInfoMapper.findByApartmentId(id.longValue());
        List<FacilityInfo> facilityInfoList = facilityInfoMapper.findFacilityByApartmentId(id);


        apartmentDetailVo.setGraphVoList(graphVoList);
        apartmentDetailVo.setLabelInfoList(labelInfoList);
        apartmentDetailVo.setFacilityInfoList(facilityInfoList);
        return apartmentDetailVo;
    }

    @Override
    public ApartmentDetailVo findApartmentDetailById2(Integer id) {
        return baseMapper.findApartmentDetailById2(id);
    }
}




